package pl.softech.gpw.candles.patterns.impl2;

import pl.softech.gpw.candles.Candle;

public class CandleGreedyEngfulsBodyRule implements IRule {

    private int engulfsBodyCount(int index, Candle[] candles) {
        
        Candle candle = candles[index];
        
        int count = 0;
        for(int i = index + 1; i < candles.length; i++) {
            if(candle.engulfsBody(candles[i])) {
                count++;
            }
        }
        
        return count;
        
    }
    
    @Override
    public boolean match(Candle[] pattern, Candle[] candles) {
        
        for(int i = 0 ; i < pattern.length - 1; i++) {
            
            if(engulfsBodyCount(i, pattern) != engulfsBodyCount(i, candles)) {
                return false;
            } 
        }
        
        return true;
    }

}
